package com.css.dzj.zfjg.modules.admpenalty.service.impl;


import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import com.css.dzj.zfjg.common.util.Constant;
import com.css.dzj.zfjg.common.util.ServiceUtil;
import com.css.dzj.zfjg.common.util.SnowflakeId;
import com.css.dzj.zfjg.common.util.UUidUtil;
import com.css.dzj.zfjg.common.util.excel.ExcelData;
import com.css.dzj.zfjg.common.util.excel.ExportExcelUtils;
import com.css.dzj.zfjg.modules.admpenalty.AdmExcelVerifyHandler;
import com.css.dzj.zfjg.modules.admpenalty.Vo.AdmExcelVo;
import com.css.dzj.zfjg.modules.admpenalty.entity.AdmPenaltyEntity;
import com.css.dzj.zfjg.modules.admpenalty.entity.QAdmPenaltyEntity;
import com.css.dzj.zfjg.modules.admpenalty.mapper.AdmPenaltyMapper;
import com.css.dzj.zfjg.modules.admpenalty.service.AdmPenaltyService;
import com.querydsl.core.QueryResults;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class AdmPenaltyServiceImpl implements AdmPenaltyService {

    @Autowired
    private AdmPenaltyMapper admPenaltyMapper;
    @Autowired
    private JPAQueryFactory jpaQueryFactory;
    @Autowired
    HttpServletRequest request;
    @Autowired
    private AdmExcelVerifyHandler admExcelVerifyHandler;

    @Override
    public QueryResults<AdmPenaltyEntity> queryPage(Pageable pageable) {

        QAdmPenaltyEntity q = QAdmPenaltyEntity.admPenaltyEntity;
        Predicate predicate = q.isNotNull().or(q.isNull());
        String orgName = ServiceUtil.getOrgName(request);
       /* if(!StringUtils.isEmpty(orgName) && null != orgName){
            if(!orgName.contains("中国")){
                predicate = ExpressionUtils.and(predicate, q.penOrgname.eq(orgName).or(q.taskStatus.eq(Constant.ISSUBMIT_PASS).and((q.penOrgname.ne(orgName)))));
            }else {
                predicate = ExpressionUtils.and(predicate, q.taskStatus.eq(Constant.ISSUBMIT_FALSE).and((q.penOrgname.ne(orgName))));
            }

        }*/
        if(!StringUtils.isEmpty(orgName) && null != orgName){
            if(orgName.contains("中国")){
                //如果为中国地震局  可以查看所有已提交的、审核通过的、申请退回的、已退回的
                predicate = ExpressionUtils.and(predicate, q.penOrgname.eq(orgName).or(q.penOrgname.ne(orgName).and(q.taskStatus.ne(Constant.ISSUBMIT_FALSE))));
            }else {
                //如果是省局，则查看本局以及其他局审核通过的
                predicate = ExpressionUtils.and(predicate, q.penOrgname.eq(orgName).or(q.penOrgname.ne(orgName).or(q.taskStatus.eq(Constant.ISSUBMIT_NOTPASS))));
            }
        }
        predicate = ExpressionUtils.and(predicate, q.flag.eq(Constant.NO_DELETE)) ;
        QueryResults<AdmPenaltyEntity> admPenaltyResults = jpaQueryFactory.selectFrom(q)
                        .where(predicate)
                        .orderBy(q.createTime.desc())
                        .offset(pageable.getOffset())
                        .limit(pageable.getPageSize())
                        .fetchResults();
                        return admPenaltyResults;
    }

    @Override
    public AdmPenaltyEntity findById(String id) {
        if(StringUtils.isEmpty(id)){

            throw new RuntimeException("参数为空");
        }
        return admPenaltyMapper.findById(id).get();
    }

    @Override
    public List<AdmPenaltyEntity> queryByIds(String ids) {
        if (com.alibaba.druid.util.StringUtils.isEmpty(ids)) {
            throw new RuntimeException("ids为空!");
        }
        List<String> idList = Arrays.asList(ids.split(","));
        List<AdmPenaltyEntity> admPenaltyEntities = admPenaltyMapper.findAllById(idList);
        return admPenaltyEntities;
    }

    @Override
    @Transactional
    public void add(AdmPenaltyEntity admPenaltyEntity) {

        try {
            if(("此案件信息已经本单位领导审定").equals(admPenaltyEntity.getIsSubmit())){
                admPenaltyEntity.setIsSubmit("1");
            }
            admPenaltyEntity.setCreateTime(new Date());
            admPenaltyEntity.setCreateUser(ServiceUtil.getLoginName(request));
            admPenaltyEntity.setPenOrgname(ServiceUtil.getOrgName(request));
            admPenaltyEntity.setFlag(Constant.NO_DELETE);
            admPenaltyEntity.setTaskStatus(Constant.ISSUBMIT_TRUE);
            admPenaltyEntity.setRecordUniqueIdentity(UUidUtil.getUuid());
            admPenaltyMapper.save(admPenaltyEntity);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    @Transactional
    public void storage(AdmPenaltyEntity admPenaltyEntity) {

        try {
            if(("此案件信息已经本单位领导审定").equals(admPenaltyEntity.getIsSubmit())){
                admPenaltyEntity.setIsSubmit("1");
            }else{
                admPenaltyEntity.setIsSubmit("0");
            }
            admPenaltyEntity.setCreateTime(new Date());
            admPenaltyEntity.setCreateUser(ServiceUtil.getLoginName(request));
            admPenaltyEntity.setPenOrgname(ServiceUtil.getOrgName(request));
            admPenaltyEntity.setFlag(Constant.NO_DELETE);
            admPenaltyEntity.setTaskStatus(Constant.ISSUBMIT_FALSE);
            admPenaltyEntity.setRecordUniqueIdentity(UUidUtil.getUuid());
            admPenaltyMapper.save(admPenaltyEntity);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    @Transactional
    public void update(AdmPenaltyEntity admPenaltyEntity) {

    }

    @Override
    @Transactional
    public Boolean delete(String id) {

        if(StringUtils.isEmpty(id)){
            return  false;
        }
        try{
            QAdmPenaltyEntity q = QAdmPenaltyEntity.admPenaltyEntity;
            jpaQueryFactory
                    .update(q)
                    .set(q.flag,Constant.DELETE)
                    .where(
                            q.flag.eq(Constant.NO_DELETE),
                            q.id.eq(id)
                    )
                    .execute();
            return true;
        }catch (Exception e){
            return false;
        }
    }

    @Override
    public QueryResults<AdmPenaltyEntity> getXzcfist(String enforceName,String enforceOrganizationSite, String enforceObject, String breakFact,
                                                     String caseSource, String taskStatus,String disposeResult,String penaltyCategory,
                                                     String enforceOrganization,String caseCategory,String releaseStartTime,
                                                     String releaseEndTime,Pageable pageable) {

        QAdmPenaltyEntity q = QAdmPenaltyEntity.admPenaltyEntity;
        Predicate predicate = q.isNotNull().or(q.isNull());
        String orgName = ServiceUtil.getOrgName(request);
        if(!StringUtils.isEmpty(orgName) && null != orgName){
            if(orgName.contains("中国")){
                //如果为中国地震局  可以查看所有已提交的、审核通过的、申请退回的、已退回的
                //predicate = ExpressionUtils.and(predicate, q.penOrgname.eq(orgName).or(q.penOrgname.ne(orgName).and(q.taskStatus.eq(Constant.ISSUBMIT_TRUE).or(q.taskStatus.eq(Constant.ISSUBMIT_BACK).or(q.taskStatus.eq(Constant.ISSUBMIT_PASS)).or(q.taskStatus.eq(Constant.ISSUBMIT_NOTPASS)).or(q.taskStatus.eq(Constant.ISSUBMIT_APPLYRECALL))))));
                predicate = ExpressionUtils.and(predicate, q.penOrgname.eq(orgName).or(q.penOrgname.ne(orgName).and(q.taskStatus.ne(Constant.ISSUBMIT_FALSE))));
            }else {
                //如果是省局，则查看本局以及其他局审核通过的
                predicate = ExpressionUtils.and(predicate, q.penOrgname.eq(orgName).or(q.penOrgname.ne(orgName).and(q.taskStatus.eq(Constant.ISSUBMIT_NOTPASS))));
            }
        }
        predicate = ("".equals(enforceName) || enforceName == null) ? predicate : ExpressionUtils.and(predicate, q.enforceName.like("%"+enforceName+"%"));
        predicate = ("".equals(enforceOrganizationSite) || enforceOrganizationSite == null) ? predicate : ExpressionUtils.and(predicate, q.enforceOrganizationSite.like("%"+enforceOrganizationSite+"%"));
        predicate = ("".equals(enforceObject) || enforceObject == null) ? predicate : ExpressionUtils.and(predicate, q.enforceObject.like("%"+enforceObject+"%"));
        predicate = ("".equals(breakFact) || breakFact == null) ? predicate : ExpressionUtils.and(predicate, q.breakFact.like("%"+breakFact+"%"));
        predicate = ("".equals(caseSource) || caseSource == null) ? predicate : ExpressionUtils.and(predicate, q.caseSource.eq(caseSource));
        predicate = ("".equals(disposeResult) || disposeResult == null) ? predicate : ExpressionUtils.and(predicate, q.disposeResult.eq(disposeResult));
        predicate = ("".equals(penaltyCategory) || penaltyCategory == null) ? predicate : ExpressionUtils.and(predicate, q.penaltyCategory.eq(penaltyCategory));
        predicate = ("".equals(enforceOrganization) || enforceOrganization == null) ? predicate : ExpressionUtils.and(predicate, q.enforceOrganization.like("%"+enforceOrganization+"%"));
        predicate = ("".equals(caseCategory) || caseCategory == null) ? predicate : ExpressionUtils.and(predicate, q.caseCategory.eq(caseCategory));
         /*只有结束时间*/
        if ((StringUtils.isEmpty(releaseStartTime)) && (!StringUtils.isEmpty(releaseEndTime))) {
            Date endDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                endDate = sf.parse(releaseEndTime+ " " + "23:59:59.999");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, q.registerTime.loe(endDate));
        }
       /* 只有开始时间 */
        if ((!StringUtils.isEmpty(releaseStartTime)) && (StringUtils.isEmpty(releaseEndTime))) {
            Date startDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
            try {
                startDate = sf.parse(releaseStartTime);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, q.registerTime.goe(startDate));
        }
       /* 时间都不为空 */
        if ((!StringUtils.isEmpty(releaseStartTime)) && (!StringUtils.isEmpty(releaseEndTime))) {
            Date startDate = null;
            Date endDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                startDate = sf.parse(releaseStartTime);
                endDate = sfd.parse(releaseEndTime+ " " + "23:59:59.999");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, q.registerTime.between(startDate, endDate));
        }
        predicate = ExpressionUtils.and(predicate, q.flag.eq(Constant.NO_DELETE)) ;

        return  jpaQueryFactory
                .selectFrom(q)
                .where(
                        predicate
                )
                .orderBy(q.createTime.desc())
                .offset(pageable.getOffset())   //起始页
                .limit(pageable.getPageSize())  //每页大小
                .fetchResults();
    }

    @Override
    public void exportAdmPenaltyToExcel(HttpServletResponse response, List<AdmPenaltyEntity> admPenaltyEntities) {
        if (admPenaltyEntities == null || admPenaltyEntities.size() < 0) {
            throw new RuntimeException("行政处罚为空");
        }
        // 创建导出实体
        ExcelData data = new ExcelData();
        data.setName("行政处罚表");
        /**
         * 设置Excel标题
         */
        ArrayList<String> titles = new ArrayList<>();
        titles.add("序号");
        titles.add("处罚行为名称");
        titles.add("实施机构地址");
        titles.add("监管对象");
        titles.add("违法事实");
        titles.add("立案时间");
        titles.add("案件类别");
        titles.add("案件来源");
        titles.add("处罚结果");
        titles.add("实施机构");
        titles.add("处罚种类");
        titles.add("任务状态");
        data.setTitles(titles);
        /**
         * 处理行数据
         */
        ArrayList<List<Object>> rows = new ArrayList<>();
        for (int i = 0; i < admPenaltyEntities.size(); i++) {
            ArrayList<Object> row = new ArrayList<>();
            row.add(String.valueOf(i + 1));
            row.add(admPenaltyEntities.get(i).getEnforceName());
            row.add(admPenaltyEntities.get(i).getEnforceOrganizationSite());
            row.add(admPenaltyEntities.get(i).getEnforceObject());
            row.add(admPenaltyEntities.get(i).getBreakFact());
            SimpleDateFormat spf = new SimpleDateFormat("yyyy-MM-dd");
            String formaTime = spf.format(admPenaltyEntities.get(i).getRegisterTime());
            row.add(formaTime);
            if ("1".equals(admPenaltyEntities.get(i).getCaseCategory())) {
                row.add("地震监测设施和观测环境保护");
            } else if ("2".equals(admPenaltyEntities.get(i).getCaseCategory())) {
                row.add("地震安全性评价和抗震设防要求管理");
            } else if ("3".equals(admPenaltyEntities.get(i).getCaseCategory()) && StringUtils.isEmpty(admPenaltyEntities.get(i).getOtherCase())) {
                row.add("其他");
            }else if (!StringUtils.isEmpty(admPenaltyEntities.get(i).getOtherCase())) {
                row.add(admPenaltyEntities.get(i).getOtherCase());
            }else{
                row.add(admPenaltyEntities.get(i).getCaseCategory());
            }

            if ("1".equals(admPenaltyEntities.get(i).getCaseSource())) {
                row.add("在行政检查中发现");
            } else if ("2".equals(admPenaltyEntities.get(i).getCaseSource())) {
                row.add("机构检测报告");
            } else if ("3".equals(admPenaltyEntities.get(i).getCaseSource())) {
                row.add("社会举报");
            } else if ("4".equals(admPenaltyEntities.get(i).getCaseSource())) {
                row.add("上级行政机关交办");
            } else if ("5".equals(admPenaltyEntities.get(i).getCaseSource())) {
                row.add("下级行政机构报请");
            } else if ("6".equals(admPenaltyEntities.get(i).getCaseSource())) {
                row.add("有关部门移送");
            }else{
                row.add(admPenaltyEntities.get(i).getCaseSource());
            }

            if ("1".equals(admPenaltyEntities.get(i).getDisposeResult())) {
                row.add("进行处罚");
            }else if ("2".equals(admPenaltyEntities.get(i).getDisposeResult())) {
                row.add("改正违法行为");
            }else if ("3".equals(admPenaltyEntities.get(i).getDisposeResult())) {
                row.add("增建抗干扰设施");
            }else if ("4".equals(admPenaltyEntities.get(i).getDisposeResult())) {
                row.add("新建地震监测设施");
            }else if ("5".equals(admPenaltyEntities.get(i).getDisposeResult()) && StringUtils.isEmpty(admPenaltyEntities.get(i).getOtherResult())) {
                row.add("其他");
            }else if (!StringUtils.isEmpty(admPenaltyEntities.get(i).getOtherResult())) {
                row.add(admPenaltyEntities.get(i).getOtherResult());
            }else{
                row.add(admPenaltyEntities.get(i).getDisposeResult());
            }

            row.add(admPenaltyEntities.get(i).getEnforceOrganization());
            if ("1".equals(admPenaltyEntities.get(i).getPenaltyCategory())) {
                row.add("警告");
            } else if ("2".equals(admPenaltyEntities.get(i).getPenaltyCategory())) {
                row.add("罚款");
            } else if ("3".equals(admPenaltyEntities.get(i).getPenaltyCategory())) {
                row.add("没收违法所得");
            }else{
                row.add(admPenaltyEntities.get(i).getPenaltyCategory());
            }


            if ("0".equals(admPenaltyEntities.get(i).getTaskStatus())) {
                row.add("未提交");
            } else if ("1".equals(admPenaltyEntities.get(i).getTaskStatus())) {
                row.add("已提交");
            } else if ("2".equals(admPenaltyEntities.get(i).getTaskStatus())) {
                row.add("已退回");
            }
            rows.add(row);
        }
        data.setRows(rows);
        try {
            // 导出
            ExportExcelUtils.exportExcel(response, "行政处罚表.xlsx", data);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public List<AdmPenaltyEntity> queryByParams(String enforceName,String enforceOrganizationSite, String enforceObject, String breakFact,
                                                String caseSource, String taskStatus,String disposeResult,String penaltyCategory,
                                                String enforceOrganization,String caseCategory,String releaseStartTime,
                                                String releaseEndTime) {

        QAdmPenaltyEntity q = QAdmPenaltyEntity.admPenaltyEntity;
        Predicate predicate = q.isNotNull().or(q.isNull());
        String orgName = ServiceUtil.getOrgName(request);
        if(!StringUtils.isEmpty(orgName) && null != orgName){
            if(orgName.contains("中国")){
                //如果为中国地震局  可以查看所有已提交的、审核通过的、申请退回的、已退回的
                predicate = ExpressionUtils.and(predicate, q.penOrgname.eq(orgName).or(q.penOrgname.ne(orgName).and(q.taskStatus.ne(Constant.ISSUBMIT_FALSE))));
            }else {
                //如果是省局，则查看本局以及其他局审核通过的
                predicate = ExpressionUtils.and(predicate, q.penOrgname.eq(orgName).or(q.penOrgname.ne(orgName).or(q.taskStatus.eq(Constant.ISSUBMIT_NOTPASS))));
            }
        }
        predicate = ("".equals(enforceName) || enforceName == null) ? predicate : ExpressionUtils.and(predicate, q.enforceName.like("%"+enforceName+"%"));
        predicate = ("".equals(enforceOrganizationSite) || enforceOrganizationSite == null) ? predicate : ExpressionUtils.and(predicate, q.enforceOrganizationSite.like("%"+enforceOrganizationSite+"%"));
        predicate = ("".equals(enforceObject) || enforceObject == null) ? predicate : ExpressionUtils.and(predicate, q.enforceObject.like("%"+enforceObject+"%"));
        predicate = ("".equals(breakFact) || breakFact == null) ? predicate : ExpressionUtils.and(predicate, q.breakFact.like("%"+breakFact+"%"));
        predicate = ("".equals(caseSource) || caseSource == null) ? predicate : ExpressionUtils.and(predicate, q.caseSource.eq(caseSource));
        predicate = ("".equals(disposeResult) || disposeResult == null) ? predicate : ExpressionUtils.and(predicate, q.disposeResult.eq(disposeResult));
        predicate = ("".equals(penaltyCategory) || penaltyCategory == null) ? predicate : ExpressionUtils.and(predicate, q.penaltyCategory.eq(penaltyCategory));
        predicate = ("".equals(enforceOrganization) || enforceOrganization == null) ? predicate : ExpressionUtils.and(predicate, q.enforceOrganization.like("%"+enforceOrganization+"%"));
        predicate = ("".equals(caseCategory) || caseCategory == null) ? predicate : ExpressionUtils.and(predicate, q.caseCategory.eq(caseCategory));
        /* 只有结束时间*/
        if ((StringUtils.isEmpty(releaseStartTime)) && (!StringUtils.isEmpty(releaseEndTime))) {
            Date endDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                endDate = sf.parse(releaseEndTime+ " " + "23:59:59.999");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, q.registerTime.loe(endDate));
        }
        /** 只有开始时间 **/
        if ((!StringUtils.isEmpty(releaseStartTime)) && (StringUtils.isEmpty(releaseEndTime))) {
            Date startDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
            try {
                startDate = sf.parse(releaseStartTime);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, q.registerTime.goe(startDate));
        }
        /** 时间都不为空 **/
        if ((!StringUtils.isEmpty(releaseStartTime)) && (!StringUtils.isEmpty(releaseEndTime))) {
            Date startDate = null;
            Date endDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                startDate = sf.parse(releaseStartTime);
                endDate = sfd.parse(releaseEndTime+ " " + "23:59:59.999");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, q.registerTime.between(startDate, endDate));
        }
        predicate = ExpressionUtils.and(predicate, q.flag.eq(Constant.NO_DELETE)) ;

        return  jpaQueryFactory
                .selectFrom(q)
                .where(
                        predicate
                )
                .orderBy(q.createTime.desc())
                .fetch();
    }

    @Override
    @Transactional
    public String uploadFile(MultipartFile file, HttpServletResponse response) {

        try {
            Integer hang;
            StringBuilder returnMsg = new StringBuilder();
            String[] head = new String[]{"处罚行为名称","实施机构","实施机构地址(XX省-XX市-XX区)","案件来源","案件类别",
                                         "处罚对象","处罚依据","案件基本情况","违法事实","立案时间(YYYY-MM-DD)",
                                         "是否进行法制审核","处罚结果","罚款金额(万元)","处罚种类","案例分析","此案件信息已经过本单位领导审核"};
            ImportParams params = new ImportParams();
            params.setHeadRows(1);
            params.setTitleRows(1);
            params.setKeyIndex(0);
            params.setStartRows(2);
            params.setNeedVerify(true);
            params.setImportFields(head);
            params.setVerifyHandler(admExcelVerifyHandler);
            ExcelImportResult<AdmExcelVo> result = ExcelImportUtil.importExcelMore(file.getInputStream(), AdmExcelVo.class, params);
            List<AdmExcelVo> list = result.getList();
            if( null !=list && list.size()>0){
                checkList(list);
            }
            Iterator it = list.iterator();
            AdmExcelVo admExcelVo;

            returnMsg.append("成功导入" + result.getList().size() + "条，失败" + result.getFailList().size() + "条<br/>");

            list.forEach((e) -> {
                AdmPenaltyEntity entity = new AdmPenaltyEntity();
                entity.setId(SnowflakeId.getId());
                BeanUtils.copyProperties(e, entity);
                this.add(entity);
            });

            if (result.isVerifyFail()) {
                it = result.getFailList().iterator();

                while(it.hasNext()) {
                    admExcelVo = (AdmExcelVo)it.next();
                    hang = admExcelVo.getRowNum()+1;
                    String msg = "";
                    returnMsg.append("第" + hang+ "行" + admExcelVo.getErrorMsg() + "<br/>");
                    returnMsg.append(msg);
                }
            }
            return returnMsg.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }
    //校验导入数据
    @Transactional
    public  List checkList(List<AdmExcelVo> list){

        List<AdmExcelVo> admPenaltyEntityList = new ArrayList<>();
        String  othercase = "";
        String otherResult = "";
        for(AdmExcelVo admList : list){

            if("在行政检查中发现".equals(admList.getCaseSource()) || "01".equals(admList.getCaseSource())){
                 admList.setCaseSource("1");
            }else if("机构检测报告".equals(admList.getCaseSource()) || "02".equals(admList.getCaseSource())){
                 admList.setCaseSource("2");
            }else if("社会举报".equals(admList.getCaseSource()) || "03".equals(admList.getCaseSource())){
                 admList.setCaseSource("3");
            }else if("上级行政机关交办".equals(admList.getCaseSource()) || "04".equals(admList.getCaseSource()) ){
                admList.setCaseSource("4");
            }else if("下级行政机构报请".equals(admList.getCaseSource()) || "05".equals(admList.getCaseSource())){
                admList.setCaseSource("5");
            }else if("有关部门移送".equals(admList.getCaseSource()) || "06".equals(admList.getCaseSource())){
                admList.setCaseSource("6");
            }

            if("地震监测设施和观测环境保护".equals(admList.getCaseCategory()) || "01".equals(admList.getCaseCategory())){
                admList.setCaseCategory("1");
            }else if("地震安全性评价和抗震设防要求管理".equals(admList.getCaseCategory()) || "02".equals(admList.getCaseCategory())){
                admList.setCaseCategory("2");
            }else{
                othercase = admList.getCaseCategory().replace("03","");
                admList.setOtherCase(othercase);
                admList.setCaseCategory("3");
            }

            if("是".equals(admList.getIsLegalCheck()) || "01".equals(admList.getIsLegalCheck())){
                admList.setIsLegalCheck("1");
            }else if("否".equals(admList.getCaseCategory()) || "02".equals(admList.getIsLegalCheck())){
                admList.setIsLegalCheck("0");
            }

            if("进行处罚".equals(admList.getDisposeResult()) || "01".equals(admList.getDisposeResult())){
                admList.setDisposeResult("1");
            }else if("改正违法行为".equals(admList.getDisposeResult()) || "02".equals(admList.getDisposeResult())){
                admList.setDisposeResult("2");
            }else if("增建抗干扰设施".equals(admList.getDisposeResult()) || "03".equals(admList.getDisposeResult())){
                admList.setDisposeResult("3");
            }
            else if("新建地震监测设施".equals(admList.getDisposeResult()) || "04".equals(admList.getDisposeResult())){
                admList.setDisposeResult("4");
            } else{
                otherResult = admList.getDisposeResult().replace("05","");
                admList.setOtherResult(otherResult);
                admList.setDisposeResult("5");

            }

            if("警告".equals(admList.getPenaltyCategory()) || "01".equals(admList.getPenaltyCategory())){
                admList.setPenaltyCategory("1");
            }else if("罚款".equals(admList.getPenaltyCategory()) || "02".equals(admList.getPenaltyCategory())){
                admList.setPenaltyCategory("2");
            }else if("没收违法所得".equals(admList.getPenaltyCategory()) || "03".equals(admList.getPenaltyCategory())){
                admList.setPenaltyCategory("3");
            }

            if("是".equals(admList.getIsSubmit()) || "01".equals(admList.getIsSubmit())){
                admList.setIsSubmit("1");
            }else if("否".equals(admList.getIsSubmit()) || "02".equals(admList.getIsSubmit())){
                admList.setIsSubmit("0");
            }

            admPenaltyEntityList.add(admList);
        }
        return admPenaltyEntityList;
    }

   

}
